package com.bishe.supermarket.controller;

import com.bishe.supermarket.pojo.Commodity;
import com.bishe.supermarket.pojo.vo.Status;
import com.bishe.supermarket.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Controller
public class CommodityController {

    String comname;
    String category;

    @Autowired
    CommodityService commodityService;

//    public String commpdityAddress(){
//
//
//        return "comCategory"
//    }
    @RequestMapping("commodityAdress")
    public String commodityAdress(HttpSession httpSession){
        List<Commodity> listAll = commodityService.selectAll();

        httpSession.setAttribute("listCategoryAll",listAll);
        return "comCategory";
    }
    //商品下架
    @RequestMapping("commoditySelect")
    public String commoditySelect(String categoryName, HttpSession httpSession){


        List<Commodity> listName = commodityService.selectByName(categoryName);
        httpSession.setAttribute("listCategoryName",listName);
        return "categorySelect";
    }

    @RequestMapping("updateCategory")
    public String updateCategory(HttpSession httpSession){

        List<String> list = new ArrayList<>();
        list.add("请选择商品类型");
        list.add("饮料");
        list.add("水果");
        list.add("零食");
        list.add("日常用品");
        list.add("其他");
        httpSession.setAttribute("lists",list);

        return "updateCategories";
    }

    @RequestMapping("updateCate")
    public String updateCate(String comName,String category,HttpSession httpSession){

        System.out.println("我是商品名称"+comName);
        System.out.println("我是商品类型"+category);

//        Status status = commodityService.judge(comName,category);

        Status status = commodityService.judge(comName,category);
        System.out.println(status.getMsg());

        httpSession.setAttribute("status",status);


        return "updateCategoryMsg";

    }

//    @RequestMapping("updateJudge")
//    public String updateJudge(HttpSession httpSession){
//
//
//
//
//    }
//添加销售记录
    @RequestMapping("addRecord")
    public String addRecord(){



        return "addRe";
    }
    //上货页面返回

    @RequestMapping("shangJiaCom")
    public String shangJiaCom( HttpSession httpSession){

        Set<String> set = commodityService.selectCategory();

        Set<String> stringSet = commodityService.selectcomName();

        httpSession.setAttribute("set",set);
        httpSession.setAttribute("stringSet",stringSet);


        return "comAdd";
    }

    //商品上架
    //接收上架信息
    @RequestMapping("receiveShangJiaInfo")
    public String receiveShangJiaInfo(String comName,String category,int comNum,HttpSession httpSession){

     Status status = commodityService.getCom(comName,category,comNum);

     httpSession.setAttribute("sstatus",status);


     return "comAddMsg";

    }
    //商品下架

    @RequestMapping("xiaJiaCom")
    public  String xiaJiaCom(HttpSession httpSession){

      List<Commodity> list =   commodityService.backName();
      httpSession.setAttribute("name",list);

        return "xiajiaComDo";
    }
    //接收下架商品信息

    @RequestMapping("receiveXiajia")
    public String receiveXiajia(String comName,int comNum,HttpSession httpSession){

        Status status = commodityService.xiaJia(comName,comNum);
        httpSession.setAttribute("xiajia",status);

        return "xiajiaComDoMsg";
    }

}
